<?php
if(!defined('inside')) die('You do not have permission to execute this file directly.');

/**
* Config class file.
*
* @author Federico Ramirez <fedekiller@gmail.com>
* @link http://code.google.com/p/akaikiwi/
* @copyright Copyright &copy; 2008-2011 Federico Ramirez
* @license http://www.opensource.org/licenses/mit-license.php MIT Licence
*/

/*
* Main configuration file of akaikiwi
*/
class Config {
	private $config;

	function __construct() {
		$this->config = array();

		if ($handle = opendir(__DIR__ . '/../../app/config')) {
			while (false !== ($file = readdir($handle))) {
				if ($file != "." && $file != ".." && strpos($file, '.php') !== FALSE) {
					require_once __DIR__ . '/../../app/config/' . $file;
					foreach($config as $k => $v) {
						$this->config[$k] = $v;
					}
				}
			}
			closedir($handle);
		}
	}

	/**
	 * Gets an item from the configuration array
	 * @param String $name The key of the configuration item you want to get
	 */
	public function get_item($name) {
		if(!array_key_exists($name, $this->config)) {
			throw new AkaikiwiException('Invalid key for configuration array.');
		}

		return $this->config[$name];
	}

	/**
	* Set the configuration item manually for this configuration instanceof
	* @param String $k The key of the configuration array
	* @param String $v The new value
	*/
	public function set_item($k, $v) {
		if(!array_key_exists($k, $this->config)) {
			throw new AkaikiwiException('Invalid key for configuration array.');
		}

		$this->config[$k] = $v;
	}
}
